package cn.fzkj.framework.exception.client;

import cn.fzkj.framework.exception.ErrorInfo;

/** 定义客户端错误码，处理由于用户操作导致的异常. */
public interface ClientErrorCode extends ErrorInfo {

    /**
     * 用户操作异常错误码枚举
     */
    enum Code implements ClientErrorCode{
        PARAM_ERROR(1,"c","d"),
        TOKEN_NOT_FIND(2,"TOKEN_NOT_FIND","token不存在");


        private Integer code;
        private String msg;
        private String extraMsg;

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        public String getExtraMsg() {
            return extraMsg;
        }

        public void setExtraMsg(String extraMsg) {
            this.extraMsg = extraMsg;
        }
        Code(Integer code, String msg, String extraMsg){
            this.code = code;
            this.msg = msg;
            this.extraMsg = extraMsg;
        }
    }

    /**
     * 快速构建一个自定义错误描述错误信息对象.
     * <p>
     *   一般用于相同的错误码,但是不同的错误描述信息(类似).
     *   比如常见的参数错误,但是可以使用参数错误的通用错误码在描述中提示调用者更具体的错误描述.
     * </p>
     * @param msg     新的错误描述
     * @return 使用自定义描述替换原有描述的信息对象副本
     */
    default ClientErrorCode as (String msg){
        ErrorInfo errorInfo = this;
        return new ClientErrorCode() {
            @Override
            public Integer getCode() {
                return errorInfo.getCode();
            }

            @Override
            public String getMsg() {
                return msg;
            }

            @Override
            public String getExtraMsg() {
                return errorInfo.getExtraMsg();
            }
        };
    }

}
